package com.lv.suyiyong.hfr.adapter

import android.view.LayoutInflater
import android.view.View
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.lv.common.base.DataBindBaseViewHolder
import com.lv.common.imp.OnPositionTListener
import com.lv.common.ktx.LoadSrc
import com.lv.common.ktx.applyGrayScale
import com.lv.common.utils.MoneyUtil
import com.lv.service.bean.SpuItemBean
import com.lv.suyiyong.hfr.R
import com.lv.suyiyong.hfr.databinding.ItemBrandBannerBinding
import com.lv.suyiyong.hfr.databinding.ItemFactoryBannerBinding
import com.lv.suyiyong.hfr.databinding.ItemFactoryBinding
import com.lv.suyiyong.hfr.databinding.ItemFactoryImagePriceBinding


/**
 * 作者： ygx
 * 创建日期：2022/6/24 8:10 PM
 * 签名： 天行健，君子以自强不息；地势坤，君子以厚德载物。
 *      _              _           _     _   ____  _             _ _
 *     / \   _ __   __| |_ __ ___ (_) __| | / ___|| |_ _   _  __| (_) ___
 *    / _ \ | '_ \ / _` | '__/ _ \| |/ _` | \___ \| __| | | |/ _` | |/ _ \
 *   / ___ \| | | | (_| | | | (_) | | (_| |  ___) | |_| |_| | (_| | | (_) |
 *  /_/   \_\_| |_|\__,_|_|  \___/|_|\__,_| |____/ \__|\__,_|\__,_|_|\___/
 *
 * You never know what you can do until you try !
 * ----------------------------------------------------------------
 *
 */
class FactoryImagePriceAdapter(
    private val datas: MutableList<SpuItemBean>,
) :
    BaseQuickAdapter<SpuItemBean, DataBindBaseViewHolder>
        (R.layout.item_factory_image_price, datas) {

    override fun convert(holder: DataBindBaseViewHolder, item: SpuItemBean) {
        val mBinding: ItemFactoryImagePriceBinding =
            holder.getBind() as ItemFactoryImagePriceBinding
//        mBinding.itemRoot = item
//        //防止列表闪烁
        mBinding.executePendingBindings()
        val layoutPosition = holder.layoutPosition
        mBinding.ivImage.LoadSrc(item.image)
        mBinding.tvName.text = item.name
        val reducedprice = item.reducedprice ?: 0.0
        if (reducedprice == 0.0) {
            mBinding.tvUnit.visibility = View.GONE
            mBinding.tvPrice.text = "面议"
        } else {
            mBinding.tvUnit.visibility = View.VISIBLE
            val price = MoneyUtil.moneydiv("$reducedprice", "100")
            mBinding.tvPrice.text = price
        }
        mBinding.ivImage.setOnClickListener {
            onViewClickListener?.onClick(layoutPosition, item)
        }

    }

    var onViewClickListener: OnPositionTListener<SpuItemBean>? = null


}